<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
     <template #action="{ record }">
       <TableAction :actions="getTableAction(record)"/>
     </template>
      <!--字段回显插槽-->
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <ApprovalAnnualKeyWorkListModel @register="registerModal" @success="handleSuccess"></ApprovalAnnualKeyWorkListModel>
  </div>
</template>

<script lang="ts" name="ApprovalAnnualKeyWorkList-ApprovalAnnualKeyWorkList" setup>
  import {reactive} from 'vue';
  import {columns, searchFormSchema} from '../ApprovalAnnualKeyWorkList/ApprovalAnnualKeyWorkList.data';
  import {list,getApprovalKeyWorkList} from '../ApprovalAnnualKeyWorkList/ApprovalAnnualKeyWorkList.api';
  import ApprovalAnnualKeyWorkListModel from "./components/ApprovalAnnualKeyWorkListModel.vue";
  import {useModal} from "@/components/Modal";
  import {useListPage} from "@/hooks/system/useListPage";
  import {BasicTable, TableAction} from "@/components/Table";
  import {getDateByPicker} from "@/utils";
  import {ApprovalTask} from "../ApprovalAnnualKeyWorkList/ApprovalAnnualKeyWorkList.api";
  //日期个性化选择
  const fieldPickers = reactive({
  });
  const queryParam = reactive<any>({});
  //注册model
  const [registerModal,{openModal}] = useModal();
  //注册table数据
  const {tableContext} = useListPage({
      tableProps:{
           title: '审批年度重点工作',
           api: getApprovalKeyWorkList,
           columns,
           canResize:true,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              if (params && fieldPickers) {
                for (let key in fieldPickers) {
                  if (params[key]) {
                    params[key] = getDateByPicker(params[key], fieldPickers[key]);
                  }
                }
              }
              return Object.assign(params, queryParam);
            },
      }
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: true,
    });
  }
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }

   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
  /**
   * 操作栏
   */
  function handleReport(record){
    return [
      {
        label: '审批',
        onClick: handleEdit.bind(null, record),
        auth: 'annualkeyworkList:yx_annualkeyworkList:approval'
      },
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      }
    ]
  }
  /**
   * 操作栏
   */
  function getTableAction(record){
    return [
      {
        label: '审批通过',
        onClick: handleApproval.bind(null, record),
        auth: 'annualkeyworkList:yx_annualkeyworkList:approval'
      },
      {
        label: '审批不通过',
        onClick: handleEdit.bind(null, record),
      }
    ]
  }
  async function handleApproval(record) {
    await ApprovalTask({id: record.id}, handleSuccess);
  }



</script>

<style lang="less" scoped>
  :deep(.ant-picker),:deep(.ant-input-number){
    width: 100%;
  }
</style>
